package com.biz.primus.ms.promotion.trans;

import com.biz.primus.model.promotion.vo.ActivityItemVo;
import com.biz.primus.model.promotion.vo.ActivityVo;
import com.biz.primus.ms.promotion.dao.ro.ActivityItemRo;
import com.biz.primus.ms.promotion.dao.ro.ActivityRo;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 活动Mapper
 *
 * @author david-liu
 */
public class ActivityRo2ActivityVoMapper implements Function<ActivityRo, ActivityVo> {

    @Override
    public ActivityVo apply(ActivityRo activityRo) {
        ActivityVo activityVo = new ActivityVo();
        activityVo.setId(activityRo.getId());
        activityVo.setName(activityRo.getName());
        activityVo.setDescription(activityRo.getDescription());
        activityVo.setLogo(activityRo.getLogo());
        activityVo.setRawHtml(activityRo.getRawHtml());
        return activityVo;
    }

    public ActivityVo doMap(ActivityRo activityRo, Function<ActivityItemRo, ActivityItemVo> itemMapper, Collection<ActivityItemRo> ros) {
        ActivityVo activityVo = this.apply(activityRo);
        List<ActivityItemVo> items = Optional.ofNullable(ros).orElse(Collections.emptyList()).stream().map(itemMapper).collect(Collectors.toList());
        activityVo.setItems(items);
        return activityVo;
    }
}
